package com.github.m6d21.sso.common.util;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2018/12/18 Tue 18:49:00
 * @since 1.0.0
 */
public class EmptyUtil {

    public static String ifNullToEmpty(String string) {
        if (null == string) {
            return "";
        }
        return string;
    }

    public static <K, V> Map<K, V> ifNullToEmpty(Map<K, V> map) {
        if (null == map) {
            return Maps.newHashMap();
        }
        return map;
    }

    public static <T> List<T> ifNullToEmpty(List<T> list) {
        if (null == list) {
            return Lists.newArrayList();
        }
        return list;
    }

    public static <T> Set<T> ifNullToEmpty(Set<T> set) {
        if (null == set) {
            return Sets.newHashSet();
        }
        return set;
    }

    public static String ifEmptyToNull(String string) {
        if (StringUtils.isEmpty(string)) {
            return null;
        }
        return string;
    }

    public static String ifBlankToNull(String string) {
        if (StringUtils.isBlank(string)) {
            return null;
        }
        return string;
    }
}
